// JavaScript Document
var thisobj1;
function initbar(id,obj)
{
	$("#"+id).addClass("pro");
	$("#"+id+" .mainIcon").html(obj.mainIcon);
	$("#"+id+" .warnIcon").html(obj.attendIcon);
	if(obj.barInfo!=null)
	{
		
		//设置第一个参数,已用量百分比
		if(obj.barInfo.percent>100)
		{
			$("#"+id+" #bgdiv").addClass("chaochu1");
		}
		else
		{
			$("#"+id+" #bgdiv").addClass("weichao1");
			$("#"+id+" #bgdiv #showdiv").addClass("weichao2");
			/*for(;true;)
			{
				var proW=$("#"+id+" #bgdiv #showdiv").width();
				setTimeout();
			}*/
			//alert(obj.barInfo.percent);
			//$("#"+id+" #bgdiv #showdiv").width(obj.barInfo.percent+"%");
			//创建刻度,总共9个刻度
			createkedu($("#"+id+" #bgdiv"),obj);
			//alert($("#"+id+" #bgdiv").html())
			localStorage.setItem(id,$("#"+id+" #bgdiv"));
			thisobj1=localStorage.getItem("call");
			
		}
		
		var showdata1='<table cellspacing="0" cellpadding="0" width="100%"><tr><td align="left">'+obj.barInfo.percentHtml+obj.barInfo.propInfo+'</td><td align="right">'+obj.barInfo.restAmount+'</td></tr></table>';
		var showdata2='<table class="rulersize" cellspacing="0" cellpadding="0" width="100%"><tr><td width="50%" align="left">0</td><td width="50%" align="right">'+obj.barInfo.totalAmount+'</td></tr></table>';
		$(showdata1).insertBefore($("#"+id+" #bgdiv"));
		$(showdata2).insertAfter($("#"+id+" #bgdiv"));
		$(".showdata").width($("#"+id+" #bgdiv").width());
	}
	else
	{
		$("#"+id+" .process").html("<div class='shouinfo' style='margin-top:3%;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+obj.shouInfo+"</div>");
	}
	var jiantou='<div style="float:right;margin-top:45px; padding-right:15px"><img src="res/index/images/right_pic.png"/></div>';
	$(jiantou).insertAfter($("#"+id+" .process"));
}

//创建刻度
function createkedu(bgdivObj,obj)
{
	
	//计算一个单位的刻度间距
	var left1=$(bgdivObj).width()/10;
	for(var i=1;i<=9;i++)
	{
		var shortimg=$("<img>").attr("src","/www/bi/res/index/images/short.png").attr("width","2").attr("height","8");
		var longimg=$("<img>").attr("src","/www/bi/res/index/images/long.png").attr("width","2").attr("height","16");
		//alert(-20*i);
		var kedudiv=$("<div>").attr("id","div"+i).addClass("kedu");
		
		if(i%2!=0)
		{
			
			kedudiv.css({
					"left":(left1*i-10)+"px",
					"top":(-10*i-6)+"px"	
					});
			var long=$("<div>");
			longimg.appendTo(long);
			long.appendTo(kedudiv);
		}
		else
		{
			kedudiv.css({
					"left":(left1*i-10)+"px",
					"top":(-10*i-11)+"px"
					});
			var baifen=i*10;
			var fontc="#000";
			if(obj.barInfo.percent<=baifen)
			{
				fontc="#fff";
			}

			
			var shuzi=$("<div>").html("<label style='color:"+fontc+";'>"+i*10+"</label>");
			var short=$("<div>");
			shortimg.appendTo(short);
			shuzi.appendTo(kedudiv);
			short.appendTo(kedudiv);
		}
		kedudiv.appendTo($(bgdivObj));
	}
	var cc=0;
	var proC=setInterval(function(){
		
		$(bgdivObj).children("#showdiv").width(cc+"%");
		//alert("cc="+cc+",obj.barInfo.percent"+Math.round(obj.barInfo.percent));
		if(cc==Math.round(obj.barInfo.percent))
		{
			clearInterval(proC);
		}
		cc+=1;
		},5);
	//$(bgdivObj).children("#showdiv").width(obj.barInfo.percent+"%");
}